<template>
  <com-main>
    <div slot="com_header">首页>订单管理>订单列表</div>
    <div slot="com_content">
      <div>
        <el-form>
          <el-form-item>
            <el-input style="width:500px;" placeholder="请输入查询的内容" v-model="searchobj.query"></el-input>
            <el-button @click="query()"><i class="el-icon-search"></i></el-button>
          </el-form-item>
        </el-form>
      </div>
      <el-table :data="ordersobj" border style="width: 100%">
        <el-table-column type="index" label="序号" width="50">
        </el-table-column>
        <el-table-column prop="order_number" label="订单编号" width="250">
        </el-table-column>
        <el-table-column prop="order_price" label="订单价格" width="250">
        </el-table-column>
        <el-table-column label="是否支付" width="250">
          <template slot-scope="{ row }">
            <el-tag v-if="row.order_pay == 0" type="danger">未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"> </el-table-column>
        <el-table-column prop="create_time" label="下单时间">
          <template slot-scope="{ row }">
            {{ row.create_time | timeMF }}
          </template>
        </el-table-column>
        <el-table-column label="操作" size="small">
          <template slot-scope="{row}">
           
            <el-button type="primary" icon="el-icon-edit" @click="updroder(row)">编辑</el-button>
             <el-button type="warning" icon="el-icon-edit" @click="checkorder(row.order_id)">订单详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div style="margintop: 50px">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="searchobj.pagenum"
          :page-sizes="[5, 10, 15, 20]"
          :page-size="pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>

        <!-- 编辑商品分类弹窗 -->
      <div>
        <el-dialog title="编辑订单" :visible.sync="isTian">
          <el-form :model="sendobj">
            <el-form-item label="订单ID" label-width="100px">
              <el-input v-model="sendobj.order_id"> </el-input>
            </el-form-item>
            <el-form-item label="订单价格" label-width="100px">
              <el-input v-model="sendobj.order_price"> </el-input>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="upddown()">确 定</el-button>
          </div>
        </el-dialog>
      </div>
    </div>
  </com-main>
</template>
<script>
import ComMain from "../../components/commain.vue";
import { api_query,api_order ,api_updorder} from "../../api/orders";
export default {
  components: {
    ComMain,
  },
  data() {
    return {
      isTian:false,
      total: 1,
      pagenum: 1,
      pagesize: 5,
      searchobj: {
        query: "", //查询参数
        pagenum: 1, //当前页码
        pagesize: 5, //每页显示条数
        user_id: "", //用户ID
        pay_status: "", // 支付状态
        is_send: "", //是否发货
        order_fapiao_title: "", //['个人','公司']
        order_fapiao_company: "", //公司名称
        order_fapiao_content: "", //发票内容
        consignee_addr: "", //	发货地址
      },
      ordersobj: [],
      id:1,
      sendobj:{}
    };
  },
  mounted() {
    this.query();
  },
  methods: {
    //获取修改订单信息
    updroder(row){
   this.isTian=true;
   this.sendobj=row;
      // let rst=await api_updorder(`orders/${row.order_id}`,row);
      // console.log(rst);
    },
    async upddown(){
      console.log(this.sendobj);
    let rst=await api_updorder(`orders/${this.sendobj.order_id}`,this.sendobj);
    let{data,meta}=rst;
    if(meta.status==201){
        this.$message.success(meta.msg);
    }else{
      this.$message.error(meta.msg);
    }
    this.isTian=false;
    // console.log(rst);
    },
    //查看订单详情
   async checkorder(order_id){
      let rst =await api_order(`orders/${order_id}`);
      // console.log(order_id);
      console.log(rst);
    },
   //查询数据方法
  //  async querycha(id){
  //     let rst =await api_order({id:id});
  //     console.log(rst);
  //     // console.log(this.searchobj.query);
  //  },
   //渲染数据
    async query() {
      let rst = await api_query(this.searchobj);
      let { data } = rst;
      this.ordersobj = data.goods;
      this.total = data.total;
      this.pagenum = data.pagenum;
      console.log(data);
      
    },
    handleSizeChange(val) {
      this.pagesize = val;
      this.query();
    },
    handleCurrentChange(val) {
      this.searchobj.pagenum = val;
      this.query();
    },
  },
};
</script>
<style>
</style>